package cn.tedu.submarine;

import javax.swing.ImageIcon;

/** 战舰 */
public class Battleship extends SeaObject {
    private int life;   //命
    /** 构造方法 */
    public Battleship(){
        super(66,26,270,124,20);
        life = 5;
    }

    /** 重写move()移动 */
    public void move(){
    }

    /** 重写getImage方法 获取图片*/
    @Override
    public ImageIcon getImage() {
        return Images.battleship;
    }

    /** 发射炸弹-----生成炸弹对象*/
    public Bomb shootBomb(){
        return new Bomb(this.getX(),this.getY());//this指代战舰
    }

    /**战舰左移*/
    public void moveLeft(){
        if (this.getX()>0){
            this.setX(this.getX()-this.getSpeed());//向左移动
        }
    }
    /**战舰右移*/
    public void moveRight(){
        if (this.getX()<World.WIDTH-this.getWidth()){
            this.setX(this.getX()+this.getSpeed());//向右移动
        }
    }

    /** 战舰增命 */
    public void addLife(int num){
        life += num;//命数增num
    }

    /** 获取命数 */
    public int getLife(){
        return life;
    }

    /** 战舰减命 */
    public void subtractLife(){
        if (life > 0){
            life--;//命数减1
        }
    }
}
















